package com.dome.network;

import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

//TCP接收端
public class Server {
    public static void main(String[] args) throws IOException {
        //创建接收端ServerSockrt对象
        //调用accept方法,如果接收到信息,accept就会生成一个对象
        //调用accept方法读入信息
        //释放资源
        ServerSocket serverSocket=new ServerSocket(7777);
        Socket accept = serverSocket.accept();
        InputStream inputStream = accept.getInputStream();
        byte[] bytes=new byte[1024];
        int len;
        while ((len=inputStream.read(bytes))!=-1){
            System.out.println(new String(bytes,0,len));
        }
    }
}
